﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;
public partial class Agency_company_biaoshu_dl : System.Web.UI.Page
{
    string straccount_type = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
        if (_Account == null)
        {
            Response.Redirect("~/", true);

        }
        straccount_type = _Account.Type.ToString();
        if (straccount_type == "1")
        {
            ToEcxul.Visible = true;
        }
        if (_Account != null)
        {
            if (int.Parse(_Account.Type) == 17 || int.Parse(_Account.Type) == 1)
            {
                showGrid();
            }
            else
            {
                Response.Write("<script>window.alert('对不起，您无权查看！');</script>");
                Response.Write("<script>window.location.href='../HomePage/Default.aspx';</script>");
            }

        }
        else
        {
            Response.Write("<script>window.alert('对不起，请重新登录！');</script>");
            Response.Write("<script>window.location.href='../HomePage/Default.aspx';</script>");
        }

    }
    protected void showGrid()
    {
        string strConditions;
        strConditions = fctConditions();
        Db db = new Db();
        DbPage dbPage = new DbPage(db);
        dbPage.Table = "company as c inner join account as a  on c.accountid=a.accountid left join (select distinct usercode_tb, 1 as Num from  company_biaoshu ,account where   usercode_tb=account.accountname and usercode_sc=account.accountname) m on m.usercode_tb= a.accountname";                                               //要查询的表明
        //要查询的表明
        dbPage.Key = "a.accountid";                                               //表的主键    
        dbPage.Where = strConditions;                                           //查询条件    
        dbPage.SelectField = "accountname,sort,companyname,a.accountid,m.num";//要显示的字段
        dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);          //要显示第几页   
        dbPage.PageSize = 15;                                                    //没有显示记录条数   
        dbPage.OrderBy = "a.accountid";        //排序字段
        System.Data.IDataReader dr = dbPage.ExecuteReader();
        GridView1.DataSource = dr;
        GridView1.DataBind();
        dr.Close();
        dr.Dispose();
        dbPage.Db.Close();
        db.Close();
        this.DbPageFlip1.DbPage = dbPage;//将数据传给控键

    }
    public string fctConditions()
    {
        HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
        string strwhere = "  checkstatus=1 and isbid_landing=1 ";
        string str_accountname = TextBox1.Text.ToString().Trim();
        string str_comname = TextBox2.Text.Trim();
        if (str_accountname != "")
        {
            strwhere += " and  accountname like '%" + str_accountname + "%'";
        }
        if (str_comname != "")
        {
            strwhere += " and companyname like '%" + str_comname + "%'";
        }



        return strwhere;


    }
    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {

        this.GridView1.Columns[0].Visible = false;

    }

    protected void ToEcxul_Click(object sender, EventArgs e)
    {
        Db db = new Db();
        System.Data.IDataReader dr;

        string _strSql = " select usercode_sc as [企业注册号],username_sc as [企业名称],usercode_tb as 代领企业注册号,username_tb as 代领企业名称,add_tjr as 标书发放人,add_time as 发放时间 from company_biaoshu ";

        dr = db.DataReader(_strSql);
        GridView2.DataSource = dr;
        GridView2.DataBind();
        db.Close();
        dr.Close();
        dr.Dispose();

        SysFun.WriteToExcel(GridView2, this.Page, "标书发放信息.xls");

    }

    public override void VerifyRenderingInServerForm(Control control)
    {
        //OverRide　为了使导出成Excel可行！

    }

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            int tb = SysFun.ToInt(DataBinder.Eval(e.Row.DataItem, "Num"));
            if (tb != 0)
            {
                e.Row.BackColor = System.Drawing.Color.Gold;
            }
        }
        e.Row.Cells[3].Visible = false;

    }
}
